package com.example.mobile2021606127cxz0429;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity2 extends AppCompatActivity implements View.OnClickListener {

    private EditText edtUser;
    private EditText edtPsw;
    private Button btnLogin;
    private Button btnRegister;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        initView();
    }

    private void initView() {
        edtUser = (EditText) findViewById(R.id.edt_user);
        edtPsw = (EditText) findViewById(R.id.edt_psw);
        btnLogin = (Button) findViewById(R.id.btn_login);
        btnRegister = (Button) findViewById(R.id.btn_register);
        btnLogin.setOnClickListener(this);
        btnRegister.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_login:
                if (edtUser.getText().toString().equals("admin") & edtPsw.getText().toString().equals("123456")) {
                    new AlertDialog.Builder(this)
                            .setTitle("登录信息")
                            .setMessage("登录成功")
                            .setPositiveButton("确定",null)
                            .create()
                            .show();
                }

                break;
            case R.id.btn_register:
                startActivity(new Intent(MainActivity2.this,MainActivity3.class));
                break;
        }
    }
}